package com.zbkj.service.model.front.vo.user;

import com.zbkj.dal.entity.user.UserBank;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

@Data
@ApiModel
public class BankInfoVO {

    @ApiModelProperty("银行卡信息编号")
    private String bankNo;

    @ApiModelProperty("银行卡号（后四位）")
    private String bankcardNo;

    @ApiModelProperty("银行卡账户名称")
    private String accountName;

    @ApiModelProperty("银行总行名称")
    private String bankName;

    @ApiModelProperty("银行总行编号")
    private String bankCode;

    public static BankInfoVO generate(UserBank userBank) {
        BankInfoVO bankInfoVO = new BankInfoVO();
        if (Objects.nonNull(userBank)) {
            if (StringUtils.isNotBlank(userBank.getBankcardNo())) {
                bankInfoVO.setBankNo(userBank.getBankcardNumber().substring((userBank.getBankcardNumber().length() - 4)));
            }
            bankInfoVO.setBankcardNo(userBank.getBankcardNo());
            bankInfoVO.setAccountName(userBank.getAccountName());
            bankInfoVO.setBankName(userBank.getBankName());
            bankInfoVO.setBankCode(userBank.getBankNumber());
        }
        return bankInfoVO;
    }
}
